package com.guan.study.easyExcelDemo.read;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.metadata.Cell;
import com.guan.study.easyExcelDemo.Teacher;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.sl.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellRangeAddress;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * @Date: 2023/7/2 15:33
 * @Author: yaobai
 * @Description: 为了通用，该监听器不做数据库相关操作。这是读取excel内容，然后返回出去。
 */
@Slf4j
@Getter
public class ReadLisitener<T> extends AnalysisEventListener<T> {

    List<T> list = new ArrayList<>();


    @Override
    public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
        log.info("表头："+headMap);
    }

    @Override
    public void invoke(T t, AnalysisContext context) {
        log.info("\n读取一条数据："+t.toString());

        list.add(t);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("\n读取excel完毕！读取到的数据 => list = {}",list);
    }

}
